Skip to content

feat: decouple SM-2 algorithm, add timezone handling, and unit tests … - #1527

Merged
KaranUnique merged 2 commits into
Canopus-Labs:securityfrom
Dev1822:feature/issue-1524
Aug 8, 2026
Merged

feat: decouple SM-2 algorithm, add timezone handling, and unit tests …#1527
KaranUnique merged 2 commits into
Canopus-Labs:securityfrom
Dev1822:feature/issue-1524

Conversation

@Dev1822

@Dev1822 Dev1822 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📝 Pull Request Description

Related Issue

Closes #1524

Summary

Extracted the calculateSM2 spaced repetition logic out of the flashcard controller and into a dedicated utility service (utils/srsAlgorithm.js). Introduced an optional timezone parameter to the algorithm so nextDueDate can accurately align with the start of the day (midnight) in the user's local timezone, rather than relying strictly on absolute server time. Finally, added a comprehensive Vitest unit testing suite to validate all repetition edge cases and timezone offsets.


Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature
  • ♻️ Refactoring
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • 🔥 Other(please describe) ______

How Has This Been Tested?

  • Wrote 10 rigorous unit tests validating again/hard/medium/easy rating boundaries, ease factor minimums, and timezone parsing (America/New_York, Australia/Sydney, etc.).
  • Ran the full backend test suite (npm run test / vitest) confirming 100% pass rate for the new algorithm logic.

Screenshots (if applicable)

N/A - Backend logic and unit test refactor only.


Checklist

  • My code follows the project's guidelines
  • I have tested my changes
  • I have updated documentation where necessary
  • I have linked the related issue
  • My changes do not introduce new warnings or errors

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f377a751-11b7-42a9-87a7-ab82873e4499

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@KaranUnique
KaranUnique changed the base branch from main to security August 8, 2026 12:10
@KaranUnique
KaranUnique merged commit e025d4d into Canopus-Labs:security Aug 8, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Decouple and Unit Test the SM-2 Space Repetition Algorithm

2 participants